/* *********
 *    Author: Jason He;
 *    Version: 0.0.1;
 *    Date: 2016-12-17;
 *    File: index.js;
 ********* */
 
function tagRedirect(ci,pl)
{
	if($('#hot-more').html()=='为您推荐')
	{
		var mycity =$('#mycity').html();
		//alert(document.cookie.split(";").length);
		for(var i=0;i<document.cookie.split(";").length;i++)
		{
			if(document.cookie.split(";")[i].split("=")[0]=='price')
			{
			   var p=document.cookie.split(";")[i].split("=")[1];
			}
		}
		var star =parseFloat(p)-(parseFloat(p)*0.5);
		var end =parseFloat(p)+(parseFloat(p)*0.5);
		if(!star){star=0}
		if(!end){end=100}
		window.location.href = "/home/index/get_car_list?or=d&ci=" + ci + "&pl=" + pl + "&pr=" + star + "-" + end;
	}
	if($('#hot-more').html()=='最新上架')
	{
	    window.location.href = "/home/index/get_car_list?or=n&ci=" + ci + "&pl=" + pl + "";
	}
	if($('#hot-more').html()=='降价急售')
	{
	    window.location.href = "/home/index/get_car_list?or=d&wat=1&ci=" + ci + "&pl=" + pl + "";
	}
	if($('#hot-more').html()=='准新车')
	{
	    window.location.href = "/home/index/get_car_list?or=d&ta=准新车&ci=" + ci + "&pl=" + pl + "";
	}
	if($('#hot-more').html()=='练手车')
	{
	    window.location.href = "/home/index/get_car_list?or=pa&ta=练手车&ci=" + ci + "&pl=" + pl + "";
	}
	if($('#hot-more').html()=='SUV')
	{
	    window.location.href = "/home/index/get_car_list?or=d&mo=SUV&ci=" + ci + "&pl=" + pl + "";
	}
}

$(document).ready(function () {
	// subnav phone validate
	$("#subnav-phone-input").change(function () {
		$("#subnav-phone-error").text("");
	});
	$("#subnav-phone-btn").click(function () {
		var phone = $("#subnav-phone-input").val();
		if (phone) {
			var reg = new RegExp(/^(1[34578]\d{9})|^(0\d{2,3}-?\d{7,8})$/);
			if (reg.test(phone)) {
				//alert("提交成功");
				$.ajax({
				  type: 'POST',
				  url: "/index.php?m=Web&c=Index&a=addPhone",
				  data: {phone:$('#subnav-phone-input').val()},
				  dataType:'json',
				  success:function(res){
					  if(res.id==1)
					  {
						  alert(res.msg);
					  }else
					  {
						  alert('出现异常，请联系客服');
					  }
				  }
				});
			} else {
				$("#subnav-phone-error").text("请填写正确的手机号码");
				$("#subnav-phone-input").focus();
				return false;
			}
		} else {
			$("#subnav-phone-error").text("请填写手机号码");
			$("#subnav-phone-input").focus();
			return false;
		}
	});

	// banner
	var mySwiper = new Swiper('#banner-slide', {
		simulateTouch: false,
		autoplay: 5000,
		autoplayDisableOnInteraction: false,
		loop: true,
		pagination: "#swiper-pagination",
		paginationClickable: true
	});

	// hot switch
	$("#index-tag li").mouseover(function () {
		var index = $(this).index();
		var text = $(this).text();
		$("#index-tag li").removeClass("cur");
		$(this).addClass("cur");
		$(".list").removeClass("cur");
		$(".list").eq(index).addClass("cur");
		$("#hot-more").html(text);
	});
});